{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a76d2dff-8e0c-4aaf-9897-b21dd4eadefa",
   "metadata": {},
   "source": [
    "kitti共有8各类别：Car、Van、Truck、Pedestrian、Person_sitting、Cyclist、Tram、Misc、DontCare\n",
    "\n",
    "DontCare先暂时不用管它\n",
    "\n",
    "kitti的格式是\n",
    "\n",
    "（来自label 0000000.txt）\n",
    "\n",
    "Pedestrian 0.00 0 -0.20 712.40 143.00 810.73 307.92 1.89 0.48 1.20 1.84 1.47 8.41 0.01\n",
    "\n",
    "     0      1   2    3    left   top  right  bottom  高   宽   米   \n",
    "     \n",
    "每一行有15个属性.\n",
    "\n",
    "0、类别\n",
    "\n",
    "1、截断程度，0~1，越大表明这个物体出现在图片中的部分越少。\n",
    "\n",
    "2、遮挡程度：0、1、2、3. 0表示完全没被遮挡，3表示遮挡过大。\n",
    "\n",
    "3、观测角度：这个有点复杂后面再想。\n",
    "\n",
    "4-7、二维检测框： left   top  right  bottom ，左上角和右下角点的坐标\n",
    "\n",
    "\n",
    "----------------\n",
    "以下是我们本次不太需要的。\n",
    "\n",
    "8-10、三维物体的尺寸：高宽长，单位为米。\n",
    "\n",
    "11-13：中心坐标：三维物体底部中心在相机坐标系下的位置坐标（x，y，z），单位为米。\n",
    "\n",
    "14：旋转角\n",
    "\n",
    "------------------\n",
    "\n",
    "而yolo需要的格式是：\n",
    "\n",
    "0、目标类别索引\n",
    "\n",
    "1、中心点x\n",
    "\n",
    "2、中心点y\n",
    "\n",
    "3、物体宽\n",
    "\n",
    "4、物体高\n",
    "\n",
    "yolo需要归一化，即无论整张图是什么大小，左上角始终为(0,0)，右下角始终为(1,1)。\n",
    "\n",
    "所以得到\n",
    "\n",
    "物体宽 = kitti[6] - kitti[4]\n",
    "\n",
    "物体长 = kitti[7] - kitti[5]\n",
    "\n",
    "物体x = (kitti[6] + kitti[4]) / 2 再归一化\n",
    "\n",
    "物体y = (kitti[7] + kitti[5]) / 2 再归一化\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4b78405d-4a1b-4808-8835-d4fb099c36e2",
   "metadata": {},
   "source": [
    "\n",
    "文件路径：\n",
    "\n",
    "label: /root/autodl-tmp/training/label_2\n",
    "\n",
    "data: /root/autodl-tmp/training/image_2\n",
    "\n",
    "\n",
    "test: /root/autodl-tmp/testing/image_2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5b11983b-c7d7-4e48-bd10-39c3b5d5cb4b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import cv2\n",
    "from MyTools import kitti_2_yolo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b3c5aad1-53fd-4d35-9cf7-b5e130b0b70a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1000\n",
      "2000\n",
      "3000\n",
      "4000\n",
      "5000\n"
     ]
    }
   ],
   "source": [
    "label_path = '/root/autodl-tmp/training/label_2' #'/root/autodl-tmp/test_label'\n",
    "img_path = '/root/autodl-tmp/training/image_2' #'/root/autodl-tmp/test_img'\n",
    "kitti_2_yolo(img_path, label_path, save_path = '../converted_label/k_2_y')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "067c0cb2-4b3b-4f0e-a5b2-06d911cb10f0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "be0a099b-89a1-4b3e-94c8-4ea16d8b9a62",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "raw",
   "id": "49326ad2-734e-43b3-8289-16fc70ed6396",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8caee0be-4399-4f90-bb98-95fb042d7211",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "96daec43-46ba-46e5-94be-ec797a30fe26",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e8873570-e885-4391-855e-3caeeb5e19d4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1478957a-bf4a-4173-b90e-a077f3a676db",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7985950f-b588-4a42-8e87-f4169db60d84",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e84e3e4d-d3ba-4c67-81e6-7d1e75c1e927",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
